<template>
  <div class="count">
    <h1>欢迎来到{{school}}学习，{{upperSchool}}</h1>
    <h2>当前求和为：{{sum}}，当前和放大10倍后：{{bigSum}}</h2>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="JIA(N)">+</button>
    <button @click="JIAN(N)">-</button>

    <button @click="jiaOdd(n)">当前和为奇数再加</button>
    <button @click="jiaWait(n)">等一等再加</button>
    <button @click="jiaServer">问问服务器到底加几</button>
  </div>
</template>

<script>
  import { mapState,mapGetters,mapActions,mapMutations } from 'vuex'
  export default {
    name:'Count',
    data() {
      return {
        n:1 //用户选择的数字
      }
    },
    computed: {
      ...mapState(['school','sum']),
      ...mapGetters(['upperSchool','bigSum'])
    },
    methods: {
      // ...mapMutations({add:'jia',sub:'jian'}),
      ...mapMutations(['JIA','JIAN']),
      // 加
     /*  add(){
        this.$store.commit('JIA',this.n)
      }, */
      // 减
      /* sub(){
        this.$store.commit('JIAN',this.n)
      }, */

      // ...mapActions({oddAdd:'jiaOdd',waitAdd:'jiaWait',serverAdd:'jiaServer'})
      ...mapActions(['jiaOdd','jiaWait','jiaServer'])

      // 奇数再加
      /* oddAdd(){
        this.$store.dispatch('jiaOdd',this.n)
      }, */

      // 等一等再加
      /* waitAdd(){
        this.$store.dispatch('jiaWait',this.n)
      }, */

      // 问问服务器再加
      /* serverAdd(){
        this.$store.dispatch('jiaServer')
      } */
    },
  }
</script>

<style scoped>
  .count {
    background-color: skyblue;
    border-radius: 10px;
    box-shadow: 0 0 10px;
    padding: 10px;
  }
  button,select {
    margin-right: 5px;
  }
</style>